2020-2021 Sunseeker Telemetry and Lighting System
timer_d_ex3_upDownMode.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430F51x2 Demo - TimerD0, Toggle P2.3/TD0.0, Up/Down Mode, 32kHz ACLK
34 //
35 // Description: Toggle P1.6 using hardware TD0.0 output. TimerD0 is configured
36 // for up/down mode with CCR0 defining period, TD0.0 also output on P1.6. In
37 // this example, CCR0 is loaded with 5 and TD0.0 will toggle P2.3 at TDCLK/2*5.
38 // Thus the output frequency on P1.6 will be the TDCLK/20. No CPU or software
39 // resources required. Normal operating mode is LPM3.
40 // As coded with TDCLK = ACLK, P2.3 output frequency = 32768/20 = 1.6384kHz
41 // ACLK = TDCLK = LFXT1 = 32kHz, MCLK = default DCO ~1.045MHz
42 //
43 // MSP430F51x2
44 // -------------------
45 // /|\ | XIN|-
46 // | | | 32kHz
47 // ---|RST XOUT|-
48 // | |
49 // | P1.6/TD0.0|-->ACLK/20
50 //
51 //******************************************************************************
52 #include "driverlib.h"
53 
54 void main(void)
55 {
56  //Stop WDT
57  WDT_A_hold(WDT_A_BASE);
58 
59  // Configure ports
60  GPIO_setAsPeripheralModuleFunctionOutputPin(
61  GPIO_PORT_P1,
62  GPIO_PIN6
63  );
64 
65  // XT1 configure
66  GPIO_setAsPeripheralModuleFunctionInputPin(
67  GPIO_PORT_PJ,
68  GPIO_PIN4 + GPIO_PIN5
69  );
70 
71  UCS_initClockSignal(UCS_FLLREF,
72  UCS_XT1CLK_SELECT,
73  UCS_CLOCK_DIVIDER_1
74  );
75 
76  UCS_turnOnLFXT1 (UCS_XT1_DRIVE_3,
77  UCS_XCAP_3
78  );
79 
80  UCS_initClockSignal(UCS_ACLK,
81  UCS_XT1CLK_SELECT,
82  UCS_CLOCK_DIVIDER_1
83  );
84 
85  Timer_D_initCompareModeParam initCompParam = {0};
86  initCompParam.compareRegister = TIMER_D_CAPTURECOMPARE_REGISTER_0;
87  initCompParam.compareInterruptEnable = TIMER_D_CAPTURECOMPARE_INTERRUPT_DISABLE;
88  initCompParam.compareOutputMode = TIMER_D_OUTPUTMODE_TOGGLE;
89  initCompParam.compareValue = 5;
90  Timer_D_initCompareMode(TIMER_D0_BASE, &initCompParam);
91 
92  Timer_D_initUpDownModeParam initUpDownParam = {0};
93  initUpDownParam.clockSource = TIMER_D_CLOCKSOURCE_ACLK;
94  initUpDownParam.clockSourceDivider = TIMER_D_CLOCKSOURCE_DIVIDER_1;
95  initUpDownParam.clockingMode = TIMER_D_CLOCKINGMODE_EXTERNAL_CLOCK;
96  initUpDownParam.timerPeriod = 5;
97  initUpDownParam.timerInterruptEnable_TDIE = TIMER_D_TDIE_INTERRUPT_DISABLE;
98  initUpDownParam.captureCompareInterruptEnable_CCR0_CCIE =
99  TIMER_D_CAPTURECOMPARE_INTERRUPT_DISABLE;
100  initUpDownParam.timerClear = TIMER_D_DO_CLEAR;
101  Timer_D_initUpDownMode(TIMER_D0_BASE, &initUpDownParam);
102 
103  Timer_D_startCounter(
104  TIMER_D0_BASE,
105  TIMER_D_UPDOWN_MODE
106  );
107 
108  __bis_SR_register(LPM3_bits); // Enter LPM3
109  __no_operation(); // For debugger
110 }
__no_operation()
void main(void)